extends Node2D

# 节点引用
@onready var monsters_container = $Monsters
@onready var start_position = $startpoint
@onready var end_position = $endpoint


# 游戏状态
var game_started = false
var game_over = false

# 技能事件信号
signal attack_event(source)  # 攻击事件
signal attack_buff_event(amount, source)  # 攻击力增益事件

func _ready():
	
	
	# 连接技能信号
	attack_event.connect(_on_attack_event)
	attack_buff_event.connect(_on_attack_buff_event)
	
	
	# 开始游戏
	start_game()

# 处理攻击事件
func _on_attack_event(source):
	
	
	# 广播给所有防御塔（万人海需要响应）
	for tower in get_tree().get_nodes_in_group("towers"):
		if is_instance_valid(tower) and tower != source:
			tower.handle_attack_event(source)

# 处理攻击力增益事件
func _on_attack_buff_event(amount, source):
	print("===== 攻击力增益事件触发 =====")
	print("来源: ", source.tower_type, " 增益值: ", amount)
	
	# 广播给所有防御塔（虎啸刀和紫玲珑需要响应）
	for tower in get_tree().get_nodes_in_group("towers"):
		if is_instance_valid(tower) and tower != source:
			tower.handle_attack_buff_event(amount, source)

# 开始游戏
func start_game():
	game_started = true
	game_over = false
	spawn_monster()

# 生成怪物（仅一次）
func spawn_monster():
	var monster_scene = preload("res://Scenes/enemies/Monster.tscn")
	var monster = monster_scene.instantiate()
	
	# 设置怪物位置和移动路径
	monster.position = start_position.position
	monster.target_position = end_position.position
	
	# 连接怪物销毁信号



# 怪物销毁回调
